package cn.wit.db.web;

import cn.wit.db.entity.AjaxResult;
import cn.wit.db.entity.Role;
import cn.wit.db.mapper.RoleMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class RoleController {

    @Autowired
    RoleMapper mapper;
    //查询
    @GetMapping("/role")
    public List<Role> getRoles(){
        return mapper.selectAll();
    }

    //插入
    @PostMapping("/role")
    public AjaxResult createRole(@RequestBody Role role){
         mapper.insert(role);
         return AjaxResult.success();
    }

    //删除
    @DeleteMapping("/role")
    public AjaxResult deleteRole(@PathVariable Role role){
         mapper.deleteByPrimaryKey(role.getId());
         return AjaxResult.success();
    }

    //修改
    @PutMapping("/role")
    public AjaxResult update(@PathVariable Role role){
         mapper.updateByPrimaryKey(role);
         return AjaxResult.success();
    }
}
